/*      						
 * Copyright 2010 Beijing Xinwei, Inc. All rights reserved.
 * 
 * History:
 * ------------------------------------------------------------------------------
 * Date    	|  Who  		|  What  
 * 2015��3��20��	| duanbokan 	| 	create the file                       
 */

package com.linewow.xhyy.nihaonew.other.country;

import java.util.Locale;

/**
 *
 * 取姓名首字母及模糊匹配查询
 *
 * <p>
 * 类详细描述
 * </p>
 *
 * @author duanbokan
 *
 */

public class GetCountryNameSort
{

	CharacterParserUtil characterParser = CharacterParserUtil.getInstance();

	String chReg = "[\\u4E00-\\u9FA5]+";// 中文字符串匹配

	/***
	 * 将名字转化为拼音并获得首字母
	 *
	 * @param name
	 * @return
	 */
	public String getSortLetter(String name)
	{
		String letter = "#";
		if (name == null)
		{
			return letter;
		}
		// 汉字转换成拼音
		String pinyin = characterParser.getSelling(name);
		String sortString = pinyin.substring(0, 1).toUpperCase(Locale.CHINESE);

		// 正则表达式，判断首字母是否是英文字母
		if (sortString.matches("[A-Z]"))
		{
			letter = sortString.toUpperCase(Locale.CHINESE);
		}
		return letter;
	}

	/***
	 * 取首字母
	 *
	 * @param sortKey
	 * @return
	 */
	public String getSortLetterBySortKey(String sortKey)
	{
		if (sortKey == null || "".equals(sortKey.trim()))
		{
			return null;
		}
		String letter = "#";
		// 汉字转换成拼音
		String sortString = sortKey.trim().substring(0, 1).toUpperCase(Locale.CHINESE);
		// 正则表达式，判断首字母是否是英文字母
		if (sortString.matches("[A-Z]"))
		{
			letter = sortString.toUpperCase(Locale.CHINESE);
		}
		return letter;
	}



}
